package com.meituan.catering.management.order.biz.model.converter;

import com.meituan.catering.management.order.api.http.model.request.SearchCateringOrderHttpRequest;
import com.meituan.catering.management.order.biz.model.request.SearchCateringOrderBizRequest;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Believe
 * Date 2022/5/27 9:59
 */
public class SearchCateringOrderBizRequestConverter {
    public static SearchCateringOrderBizRequest toSearchCateringOrderBizRequest(SearchCateringOrderHttpRequest searchCateringOrderHttpRequest){
        SearchCateringOrderBizRequest searchCateringOrderBizRequest = new SearchCateringOrderBizRequest();
        searchCateringOrderBizRequest.setPageIndex(searchCateringOrderHttpRequest.getPageIndex());
        searchCateringOrderBizRequest.setPageSize(searchCateringOrderHttpRequest.getPageSize());
        searchCateringOrderBizRequest.setCondition(toCondition(searchCateringOrderHttpRequest.getCondition()));
        searchCateringOrderBizRequest.setSortFields(toSortField(searchCateringOrderHttpRequest.getSortFields()));
        return searchCateringOrderBizRequest;
    }

    public static List<SearchCateringOrderBizRequest.SortField> toSortField(List<SearchCateringOrderHttpRequest.SortField> sortFields){
       List<SearchCateringOrderBizRequest.SortField> fieldList = new ArrayList<>();
        for (SearchCateringOrderHttpRequest.SortField sortField : sortFields) {
            SearchCateringOrderBizRequest.SortField field = new SearchCateringOrderBizRequest.SortField();
            field.setField(sortField.getField());
            field.setAsc(sortField.getAsc());
            fieldList.add(field);
        }
        return fieldList;
    }

    public static SearchCateringOrderBizRequest.Condition toCondition(SearchCateringOrderHttpRequest.Condition condition){
        SearchCateringOrderBizRequest.Condition bizCondition = new SearchCateringOrderBizRequest.Condition();
        bizCondition.setStatus(condition.getStatus());
        bizCondition.setTableNo(condition.getTableNo());
        bizCondition.setCustomerCount(condition.getCustomerCount());
        bizCondition.setTotalPrice(toTotalPriceRange(condition.getTotalPrice()));
        return bizCondition;
    }

    public static SearchCateringOrderBizRequest.TotalPriceRange toTotalPriceRange(SearchCateringOrderHttpRequest.TotalPriceRange
                                                                                   totalPriceRange){
        SearchCateringOrderBizRequest.TotalPriceRange bizTotalPrice = new SearchCateringOrderBizRequest.TotalPriceRange();
        bizTotalPrice.setFrom(totalPriceRange.getFrom());
        bizTotalPrice.setTo(totalPriceRange.getTo());
        return bizTotalPrice;
    }
}
